#include <freertos/stream_buffer.h>

StreamBufferHandle_t streambuffer;
void writeBufferTask(void*)
{
  char data[8] = {0};
  static uint16_t count = 0;
  static uint16_t index = 0;
  while(1)
  {
    sprintf(data, "%d", count++);
    xStreamBufferSend(streambuffer, (void*)data, sizeof(data), 1000);
    vTaskDelay(100);
  }
}

void readBufferTask(void*)
{
  char data[64] = {0};
  uint8_t revLength = 0;
  while(1)
  {
    revLength = xStreamBufferReceive(streambuffer, (void*)data, sizeof(data), 1000);
    if(revLength > 0)
    {
      Serial.println(data);
    }
    else
    {
      Serial.println("no data........");
    }
  }
}

void setup()
{
  Serial.begin(115200);
  streambuffer = xStreamBufferCreate(256, 1);
  if(streambuffer == NULL)
  {
    Serial.println("xStreamBufferCreate failed, System restart.");
    ESP.restart();
  }
  xTaskCreate(writeBufferTask, "writeBufferTask", 2048, nullptr, 1, nullptr);
  vTaskDelay(3000);
  xTaskCreate(readBufferTask, "readBufferTask", 2048, nullptr, 1, nullptr);
}

void loop() {
  // put your main code here, to run repeatedly:

}
